package com.senney.nio;

import java.io.File;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author lanmengye@outlook.com
 * @Date 2020/12/29 21:51
 */
public class FileChannel02 {
    public static void main(String[] args) throws Exception {
        File file = new File("D:\\file01.txt");
        FileInputStream inputStream = new FileInputStream(file);
        FileChannel fileChannel = inputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());
        fileChannel.read(byteBuffer);
        System.out.println(new String(byteBuffer.array()));
        inputStream.close();
    }
}
